package com.ruoyi.InboundManagement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.InboundManagement.domain.MaterialReturnInbound;
import com.ruoyi.InboundManagement.service.IMaterialReturnInboundService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 退料入库管理Controller
 * 
 * @author admin
 * @date 2024-07-02
 */
@RestController
@RequestMapping("/InboundManagement/materialReturnInbound")
public class MaterialReturnInboundController extends BaseController
{
    @Autowired
    private IMaterialReturnInboundService materialReturnInboundService;

    /**
     * 查询退料入库管理列表
     */
    @PreAuthorize("@ss.hasPermi('InboundManagement:materialReturnInbound:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialReturnInbound materialReturnInbound)
    {
        startPage();
        List<MaterialReturnInbound> list = materialReturnInboundService.selectMaterialReturnInboundList(materialReturnInbound);
        return getDataTable(list);
    }

    /**
     * 导出退料入库管理列表
     */
    @PreAuthorize("@ss.hasPermi('InboundManagement:materialReturnInbound:export')")
    @Log(title = "退料入库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialReturnInbound materialReturnInbound)
    {
        List<MaterialReturnInbound> list = materialReturnInboundService.selectMaterialReturnInboundList(materialReturnInbound);
        ExcelUtil<MaterialReturnInbound> util = new ExcelUtil<MaterialReturnInbound>(MaterialReturnInbound.class);
        util.exportExcel(response, list, "退料入库管理数据");
    }

    /**
     * 获取退料入库管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('InboundManagement:materialReturnInbound:query')")
    @GetMapping(value = "/{returnId}")
    public AjaxResult getInfo(@PathVariable("returnId") Long returnId)
    {
        return success(materialReturnInboundService.selectMaterialReturnInboundByReturnId(returnId));
    }

    /**
     * 新增退料入库管理
     */
    @PreAuthorize("@ss.hasPermi('InboundManagement:materialReturnInbound:add')")
    @Log(title = "退料入库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialReturnInbound materialReturnInbound)
    {
        return toAjax(materialReturnInboundService.insertMaterialReturnInbound(materialReturnInbound));
    }

    /**
     * 修改退料入库管理
     */
    @PreAuthorize("@ss.hasPermi('InboundManagement:materialReturnInbound:edit')")
    @Log(title = "退料入库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialReturnInbound materialReturnInbound)
    {
        return toAjax(materialReturnInboundService.updateMaterialReturnInbound(materialReturnInbound));
    }

    /**
     * 删除退料入库管理
     */
    @PreAuthorize("@ss.hasPermi('InboundManagement:materialReturnInbound:remove')")
    @Log(title = "退料入库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{returnIds}")
    public AjaxResult remove(@PathVariable Long[] returnIds)
    {
        return toAjax(materialReturnInboundService.deleteMaterialReturnInboundByReturnIds(returnIds));
    }
}
